class Solution
{
public:
    vector<int> fullBloomFlowers(vector<vector<int>> &flowers, vector<int> &people)
    {
        int n = people.size();
        vector<int> peopleIdx(n);
        iota(peopleIdx.begin(), peopleIdx.end(), 0);
        sort(peopleIdx.begin(), peopleIdx.end(), [&](int i, int j)
             { return people[i] < people[j]; });

        int flowerNum = flowers.size();
        vector<int> startDays(flowerNum);
        vector<int> endDays(flowerNum);
        for (int i = 0; i < flowerNum; ++i)
        {
            startDays[i] = flowers[i][0];
            endDays[i] = flowers[i][1];
        }
        sort(startDays.begin(), startDays.end());
        sort(endDays.begin(), endDays.end());

        vector<int> ans(n);
        int i = 0, j = 0;
        int bloomCount = 0;
        for (int idx : peopleIdx)
        {
            while (i < flowerNum && startDays[i] <= people[idx])
            {
                ++bloomCount;
                ++i;
            }
            while (j < flowerNum && endDays[j] < people[idx])
            {
                --bloomCount;
                ++j;
            }
            ans[idx] = bloomCount;
        }
        return ans;
    }
};